package top.wilsonlv.jaguar.oauth2.security.config;

import lombok.RequiredArgsConstructor;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import top.wilsonlv.jaguar.oauth2.security.component.RestClientHttpRequestInterceptor;

import java.util.List;

/**
 * @author lvws
 * @since 2022/8/18
 */
@Configuration
@RequiredArgsConstructor
public class InnerRestTemplateConfigurer {

    private final RestClientHttpRequestInterceptor restClientHttpRequestInterceptor;

    @Bean
    @LoadBalanced
    public RestTemplate innerRestTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
        interceptors.add(restClientHttpRequestInterceptor);
        return restTemplate;
    }

}
